﻿using System;
using System.Data;
using System.Data.SqlClient;
using VMuktiAPI;

namespace VMukti.DataAccess
{
    public class ClsRecordingDataService : ClsRecordingDataServiceBase
    {

        public void User_Save(ref int ID, string ServerIP, string ServerPort, string UserName, string DirectoryName, string Password,string strTag)
        {
            try
            {
                SqlCommand cmd;
                ExecuteNonQuery(out cmd, "spAERecordingFTPServer",
                    CreateParameter("@pID", SqlDbType.Int, ID),
                    CreateParameter("@pServerIP", SqlDbType.NVarChar, ServerIP),
                    CreateParameter("@pServerPort", SqlDbType.NVarChar, ServerPort),
                    CreateParameter("@pUserName", SqlDbType.NVarChar, UserName),
                    CreateParameter("@pDirectoryName", SqlDbType.NVarChar, DirectoryName),
                    CreateParameter("@pPassword", SqlDbType.NVarChar, Password),
                    CreateParameter("@pTag", SqlDbType.NVarChar, strTag));

                cmd.Dispose();
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "VMukti--:--DATA ACCess--:--FTPConfiguration--:--ClsUserDataService.cs--:--User_Save()--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);
            }
        }

        public void SetFTPDetails(string strTag)
        {
            try
            { 
                SqlCommand cmd;
                DataSet myDS = ExecuteDataSet(out cmd, "spAEGetRecordingFTPDetail",
                    CreateParameter("@pTag", SqlDbType.NVarChar, strTag, ParameterDirection.Input));
                cmd.Dispose();

                if (myDS.Tables[0].Rows.Count > 0)
                {
                    VMuktiInfo.FTPServerIP = myDS.Tables[0].Rows[0][1].ToString();
                    VMuktiInfo.FTPPort= myDS.Tables[0].Rows[0][2].ToString();
                    VMuktiInfo.FTPUserName = myDS.Tables[0].Rows[0][3].ToString();
                    VMuktiInfo.FTPDirPath = myDS.Tables[0].Rows[0][4].ToString();
                    VMuktiInfo.FTPPassword = myDS.Tables[0].Rows[0][5].ToString();
                }
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "VMukti--:--DATA ACCess--:--FTPConfiguration--:--ClsUserDataService.cs--:--User_Save()--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);                
            }
        }
    }
}
